﻿
    using Maticsoft.DBUtility;

    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Utils;

    public partial class WebPage_DingDan_WeiFaHuo : OrderBBasePage
    {

        private string expresshtml = string.Empty;
        protected bool result = true;

        protected void datacontainer_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item))
            {
                DataRowView dataItem = (DataRowView)e.Item.DataItem;
                if (dataItem != null)
                {
                    Repeater repeater = (Repeater)e.Item.FindControl("teamcontainer");
                    repeater.DataSource = DbHelperSQL.SelectByFilter("*", string.Empty, "teamid asc", "(select t.*,product from(select ISNULL(teamid,team_id) as teamid,ISNULL(num,quantity) as num,ISNULL([orderdetail].result,[Order].result) as result from [Order] left join [orderdetail] on([Order].Id=[orderdetail].Order_id) where [Order].Id=" + dataItem["order_id"] + ")t left join [Team] on(t.teamid=Team.Id))t");
                    repeater.DataBind();
                }
            }
        }

        protected string GetExpressHtml(object orderid)
        {
            return string.Format(this.ExpressHtml, orderid);
        }

        protected override void OnLoad(EventArgs e)
        {
            string str;
            string absoluteUri;
            base.OnLoad(e);
            this.HeaderControl1.Select = "order";
            int @int = Helper.GetInt(base.Request["id"], 0);
            int num2 = Helper.GetInt(base.Request["key"], 1);
            if (@int > 0)
            {
                str = ActionHelper.Manager_Cash(@int, base.AsUser.Id);
                if (str == string.Empty)
                {
                    base.SetSuccess("订单ID" + @int + "更改为已付款成功");
                }
                else
                {
                    this.SetError(str);
                }
                absoluteUri = base.Request.Url.AbsoluteUri;
                if (base.Request.UrlReferrer != null)
                {
                    absoluteUri = base.Request.UrlReferrer.AbsoluteUri;
                }
                base.Response.Redirect(absoluteUri);
                base.Response.End();
            }
            else
            {
                @int = Helper.GetInt(base.Request["delete"], 0);
                if (@int > 0)
                {
                    str = ActionHelper.Manager_DeleteOrder(@int, base.AsUser.Id);
                    if (str == string.Empty)
                    {
                        base.SetSuccess("订单ID" + @int + "删除成功");
                    }
                    else
                    {
                        this.SetError(str);
                    }
                    absoluteUri = base.Request.Url.AbsoluteUri;
                    if (base.Request.UrlReferrer != null)
                    {
                        absoluteUri = base.Request.UrlReferrer.AbsoluteUri;
                    }
                    base.Response.Redirect(absoluteUri);
                    base.Response.End();
                }
                else
                {
                    this.Page.Header.Controls.Add(new LiteralControl("<script src='" + base.WebRoot + "upfile/js/datePicker/WdatePicker.js'></script>\r\n"));
                    int currentpage = 1;
                    string whereString = this.dingdansearch1.GetWhereString();
                    string orderbystr = "pay_time asc";
                    whereString = whereString + " and Express='Y' and Express_id=0 and state='pay' ";
                    if (base.Request.HttpMethod == "GET")
                    {
                        currentpage = Helper.GetInt(base.Request.QueryString["page"], 1);
                    }
                    else
                    {
                        base.Response.Redirect(string.Format(this.dingdansearch1.GetUrl(), 1));
                        base.Response.End();
                        return;
                    }
                    Pagers pagers = DbHelperSQL.SelectByPager("*", whereString, orderbystr, currentpage, 30, "(select [Order].Id as order_id,User_id,Email,Username,Quantity,Origin,Service,Credit,[order].Money as order_money,Express,[Order].Create_time as order_create_time,Pay_time,[user].mobile as user_mobile,state,team_id,pay_id,Express_no,[order].mobile as order_mobile,Express_id,[order].Address as order_address from [Order] inner join [User] on([Order].User_id=[User].Id))t", string.Empty, string.Empty);
                    this.datacontainer.DataSource = pagers.MyData;
                    this.datacontainer.DataBind();
                    string url = this.dingdansearch1.GetUrl();
                    this.ordermenu1.Menu = 6;
                    DataTable table = new DataTable();
                    using (ASDhtDataBase base2 = new ASDhtDataBase(false))
                    {
                        table = base2.SqlExecDatatable("select id,Name from Category where zone='express' order by Sort_order desc");
                    }
                    if (table.Rows.Count == 0)
                    {
                        this.result = false;
                        this.SetError("请先设置快递公司！");
                    }
                }
            }
        }

        protected string ExpressHtml
        {
            get
            {
                if (this.expresshtml == string.Empty)
                {
                    this.expresshtml = "<select id='order_express_id_{0}'>";
                    DataTable table = new DataTable();
                    using (ASDhtDataBase base2 = new ASDhtDataBase(false))
                    {
                        table = base2.SqlExecDatatable("select id,Name from Category where zone='express' order by Sort_order desc");
                    }
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        DataRow row = table.Rows[i];
                        this.expresshtml = string.Concat(new object[] { this.expresshtml, "<option value='", row["id"], "'>", row["name"], "</option>" });
                    }
                    this.expresshtml = this.expresshtml + "</select>";
                }
                return this.expresshtml;
            }
        }
    }

